import 'package:flutter/material.dart';

class MtTop extends StatelessWidget {
  const MtTop({super.key});

  static List titleObj = [
    {"title": "点菜", "subTitle": "", "isActive": true},
    {"title": "评价", "subTitle": "1796", "isActive": false},
    {"title": "商家", "subTitle": "", "isActive": false},
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 50,
      padding: const EdgeInsets.symmetric(horizontal: 8),
      child: Row(children: [
        Expanded(
            child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: titleObj.map((item) {
            return _title(item["title"], item["subTitle"], item["isActive"]);
          }).toList(),
        )),
        _search()
      ]),
    );
  }

  Widget _title(String title, String subTitle, bool isActive) {
    return SizedBox(
      height: 50,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              Text(title, style: const TextStyle(fontSize: 16)),
              Text(subTitle,
                  style: const TextStyle(fontSize: 12, color: Colors.black54)),
            ],
          ),
          const SizedBox(height: 5),
          isActive
              ? Container(
                  width: 20,
                  height: 1,
                  color: Colors.orange,
                )
              : Container(
                  width: 20,
                  height: 1,
                  color: Colors.transparent,
                ),
        ],
      ),
    );
  }

  Widget _search() {
    return Container(
      width: 130,
      height: 30,
      margin: const EdgeInsets.only(left: 10),
      decoration: BoxDecoration(
        color: Colors.grey[200],
        borderRadius: BorderRadius.circular(15),
      ),
      child: const Row(
        children: [
          SizedBox(
            width: 5,
          ),
          Icon(
            Icons.search,
            color: Colors.black26,
            size: 20,
          ),
          Text("搜索", style: TextStyle(fontSize: 14, color: Colors.black26)),
        ],
      ),
    );
  }
}
